﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsCatchParseContent
    {
        public int Add(KeRui.Model.CmsCatchParseContent model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@ParseContentID", SqlDbType.Int, 4), new SqlParameter("@ParseContentName", SqlDbType.NVarChar, 50), new SqlParameter("@IsUsing", SqlDbType.Int, 4), new SqlParameter("@ContentEncoding", SqlDbType.NVarChar, 50), new SqlParameter("@ContentParseBegin", SqlDbType.NVarChar), new SqlParameter("@ContentParseEnd", SqlDbType.NVarChar), new SqlParameter("@ContentParseTags", SqlDbType.NVarChar), new SqlParameter("@ContentParseAttrs", SqlDbType.NVarChar), new SqlParameter("@ContentParseRule", SqlDbType.NVarChar), new SqlParameter("@ContentPageParseRule", SqlDbType.NVarChar), new SqlParameter("@BlackList", SqlDbType.NVarChar), new SqlParameter("@WhileList", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.Int, 4), new SqlParameter("@CreateUserName", SqlDbType.NVarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), 
                new SqlParameter("@UpdateUserID", SqlDbType.Int, 4), new SqlParameter("@UpdateUserName", SqlDbType.NVarChar, 50)
             };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.ParseContentName;
            parameters[2].Value = model.IsUsing;
            parameters[3].Value = model.ContentEncoding;
            parameters[4].Value = model.ContentParseBegin;
            parameters[5].Value = model.ContentParseEnd;
            parameters[6].Value = model.ContentParseTags;
            parameters[7].Value = model.ContentParseAttrs;
            parameters[8].Value = model.ContentParseRule;
            parameters[9].Value = model.ContentPageParseRule;
            parameters[10].Value = model.BlackList;
            parameters[11].Value = model.WhileList;
            parameters[12].Value = model.CreateTime;
            parameters[13].Value = model.CreateUserID;
            parameters[14].Value = model.CreateUserName;
            parameters[15].Value = model.UpdateTime;
            parameters[0x10].Value = model.UpdateUserID;
            parameters[0x11].Value = model.UpdateUserName;
            DbHelperSQL.RunProcedure("CmsCatchParseContent_ADD", parameters, out num);
            return (int) parameters[0].Value;
        }

        public void Delete(int ParseContentID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseContentID", SqlDbType.Int, 4) };
            parameters[0].Value = ParseContentID;
            DbHelperSQL.RunProcedure("CmsCatchParseContent_Delete", parameters, out num);
        }

        public bool Exists(int ParseContentID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseContentID", SqlDbType.Int, 4) };
            parameters[0].Value = ParseContentID;
            return (DbHelperSQL.RunProcedure("CmsCatchParseContent_Exists", parameters, out num) == 1);
        }

        public KeRui.Model.CmsCatchParseContent GetModel(int ParseContentID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseContentID", SqlDbType.Int, 4) };
            parameters[0].Value = ParseContentID;
            KeRui.Model.CmsCatchParseContent content = new KeRui.Model.CmsCatchParseContent();
            DataSet set = DbHelperSQL.RunProcedure("CmsCatchParseContent_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ParseContentID"].ToString() != "")
                {
                    content.ParseContentID = int.Parse(set.Tables[0].Rows[0]["ParseContentID"].ToString());
                }
                content.ParseContentName = set.Tables[0].Rows[0]["ParseContentName"].ToString();
                if (set.Tables[0].Rows[0]["IsUsing"].ToString() != "")
                {
                    content.IsUsing = int.Parse(set.Tables[0].Rows[0]["IsUsing"].ToString());
                }
                content.ContentEncoding = set.Tables[0].Rows[0]["ContentEncoding"].ToString();
                content.ContentParseBegin = set.Tables[0].Rows[0]["ContentParseBegin"].ToString();
                content.ContentParseEnd = set.Tables[0].Rows[0]["ContentParseEnd"].ToString();
                content.ContentParseTags = set.Tables[0].Rows[0]["ContentParseTags"].ToString();
                content.ContentParseAttrs = set.Tables[0].Rows[0]["ContentParseAttrs"].ToString();
                content.ContentParseRule = set.Tables[0].Rows[0]["ContentParseRule"].ToString();
                content.ContentPageParseRule = set.Tables[0].Rows[0]["ContentPageParseRule"].ToString();
                content.BlackList = set.Tables[0].Rows[0]["BlackList"].ToString();
                content.WhileList = set.Tables[0].Rows[0]["WhileList"].ToString();
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    content.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["CreateUserID"].ToString() != "")
                {
                    content.CreateUserID = int.Parse(set.Tables[0].Rows[0]["CreateUserID"].ToString());
                }
                content.CreateUserName = set.Tables[0].Rows[0]["CreateUserName"].ToString();
                if (set.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    content.UpdateTime = DateTime.Parse(set.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["UpdateUserID"].ToString() != "")
                {
                    content.UpdateUserID = int.Parse(set.Tables[0].Rows[0]["UpdateUserID"].ToString());
                }
                content.UpdateUserName = set.Tables[0].Rows[0]["UpdateUserName"].ToString();
                return content;
            }
            return null;
        }

        public int Update(KeRui.Model.CmsCatchParseContent model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@ParseContentID", SqlDbType.Int, 4), new SqlParameter("@ParseContentName", SqlDbType.NVarChar, 50), new SqlParameter("@IsUsing", SqlDbType.Int, 4), new SqlParameter("@ContentEncoding", SqlDbType.NVarChar, 50), new SqlParameter("@ContentParseBegin", SqlDbType.NVarChar), new SqlParameter("@ContentParseEnd", SqlDbType.NVarChar), new SqlParameter("@ContentParseTags", SqlDbType.NVarChar), new SqlParameter("@ContentParseAttrs", SqlDbType.NVarChar), new SqlParameter("@ContentParseRule", SqlDbType.NVarChar), new SqlParameter("@ContentPageParseRule", SqlDbType.NVarChar), new SqlParameter("@BlackList", SqlDbType.NVarChar), new SqlParameter("@WhileList", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUserID", SqlDbType.Int, 4), new SqlParameter("@CreateUserName", SqlDbType.NVarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), 
                new SqlParameter("@UpdateUserID", SqlDbType.Int, 4), new SqlParameter("@UpdateUserName", SqlDbType.NVarChar, 50)
             };
            parameters[0].Value = model.ParseContentID;
            parameters[1].Value = model.ParseContentName;
            parameters[2].Value = model.IsUsing;
            parameters[3].Value = model.ContentEncoding;
            parameters[4].Value = model.ContentParseBegin;
            parameters[5].Value = model.ContentParseEnd;
            parameters[6].Value = model.ContentParseTags;
            parameters[7].Value = model.ContentParseAttrs;
            parameters[8].Value = model.ContentParseRule;
            parameters[9].Value = model.ContentPageParseRule;
            parameters[10].Value = model.BlackList;
            parameters[11].Value = model.WhileList;
            parameters[12].Value = model.CreateTime;
            parameters[13].Value = model.CreateUserID;
            parameters[14].Value = model.CreateUserName;
            parameters[15].Value = model.UpdateTime;
            parameters[0x10].Value = model.UpdateUserID;
            parameters[0x11].Value = model.UpdateUserName;
            DbHelperSQL.RunProcedure("CmsCatchParseContent_Update", parameters, out num);
            return num;
        }
    }
}

